


//
//  MeTableViewCell.m
//  庐山通
//
//  Created by zcj on 15-11-2.
//  Copyright (c) 2015年 郑朝军. All rights reserved.
//

#import "MeTableViewCell.h"
#import "Item.h"
#import "SwitchItem.h"
#import "ArrayItem.h"
#import <UIKit/UIKit.h>
#import "Grouble.h"


@interface MeTableViewCell()
/**
 *  箭头
 */
@property (strong, nonatomic) UIImageView *arrowView;
/**
 *  开关
 */
@property (strong, nonatomic) UISwitch *switchView;

@end
@implementation MeTableViewCell
- (UISwitch *)switchView
{
    if (_switchView == nil) {
        _switchView = [[UISwitch alloc] init];
    }
    return _switchView;
}

- (UIImageView *)arrowView
{
    if (_arrowView == nil) {
        _arrowView = [[UIImageView alloc] initWithImage:[UIImage imageWithName:@"navigationbar_back_highlighted_os7"]];
    }
    return _arrowView;
}
+ (instancetype)MeTableViewCell:(UITableView *)tableview
{
    static NSString * ID = @"mecell";
    MeTableViewCell * cell = [tableview dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[MeTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    return cell;
}
// 设置每一个item
- (void)setItemsTitle:(Item *)itemsTitle
{
    _itemsTitle = itemsTitle;
    
    // 1.图标
    if (self.itemsTitle.icon) {
        self.imageView.image = [UIImage imageWithName:self.itemsTitle.icon];
    }
    
    // 2.标题
    self.textLabel.text = self.itemsTitle.title;
    
    [self setRight];

}
- (void)setRight
{
    if ([self.itemsTitle isKindOfClass:[SwitchItem class]])
    { // 右边是开关
        self.accessoryView = self.switchView;
    }
    else if ([self.itemsTitle isKindOfClass:[ArrayItem class]])
    { // 右边是箭头
        self.accessoryView = self.arrowView;
    }
    else { // 右边没有东西
        self.accessoryView = nil;
    }

}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.textLabel.textColor = [UIColor clearColor];
        self.textLabel.textColor = [UIColor blackColor];
        self.textLabel.font = [UIFont boldSystemFontOfSize:15];
        
        UIImageView * imageView = [[UIImageView alloc]init];
        [self addSubview:imageView];
        self.arrowView = imageView;
   
    }
    return self;
}
- (void)setFrame:(CGRect)frame
{
    // frame的原点坐标
    frame.origin.x = 5;
    // 设置这个起始宽度
    frame.size.width -= 10;
    [super setFrame:frame];
    
}
- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
